package entity

import (
	"context"
	"time"

	"github.com/LyricTian/gin-admin/v7/internal/app/schema"
	"github.com/LyricTian/gin-admin/v7/pkg/util/structure"
	"github.com/jinzhu/gorm"
)

// GetGroupHomeDB 获取group_home存储
func GetGroupHomeDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
	return GetDBWithModel(ctx, defDB, new(GroupHome))
}

// SchemaGroupHome group_home对象
type SchemaGroupHome schema.GroupHome

// ToGroupHome 转换为group_home实体
func (a SchemaGroupHome) ToGroupHome() *GroupHome {
	item := new(GroupHome)
	structure.Copy(a, item)
	return item
}

// GroupHome group_home实体
type GroupHome struct {
	ID        string     `gorm:"column:id;primary_key;size:36;"`
	GroupId   string     `gorm:"column:group_id;size:36;"`      // 群ID
	ContentId string     `gorm:"size:36;column:content_id;"`    // 内容ID
	Creator   string     `gorm:"size:36;index;column:creator;"` // 创建者
	CreatedAt time.Time  `gorm:"column:created_at;index;"`
	UpdatedAt time.Time  `gorm:"column:updated_at;index;"`
	DeletedAt *time.Time `gorm:"column:deleted_at;index;"`
}

// ToSchemaGroupHome 转换为group_home对象
func (a GroupHome) ToSchemaGroupHome() *schema.GroupHome {
	item := new(schema.GroupHome)
	structure.Copy(a, item)
	return item
}

// GroupHomes group_home列表
type GroupHomes []*GroupHome

// ToSchemaGroupHomes 转换为group_home对象列表
func (a GroupHomes) ToSchemaGroupHomes() []*schema.GroupHome {
	list := make([]*schema.GroupHome, len(a))
	for i, item := range a {
		list[i] = item.ToSchemaGroupHome()
	}
	return list
}
